package com.servlet.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.tomcat.util.buf.Utf8Encoder;

import com.servlet.entity.User;
import com.servlet.service.UserService;

/**
 * 添加用户
 * @author smfx1314
 *
 */
@WebServlet("/saveUser.do")
public class SaveUser extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//获取用户信息
		String name=request.getParameter("name");
		String  age = request.getParameter("age");
		String addrs = request.getParameter("addrs");
		User user = new User();
		user.setName(name);
		user.setAge(age);
		user.setAddrs(addrs);
		UserService userService = new UserService();
		int count = userService.save(user);
		request.getSession().setAttribute("msg", "成功添加了"+count+"条记录");
		response.setContentType("text/html;charset=utf-8");
		response. setCharacterEncoding("UTF-8");
		response.sendRedirect("listUser.do");
	}

}
